## R file that produces A7, A8, A9, A13, A18, A23, A28

rm(list = ls())

setwd("/Users/sparshasaha/Dropbox/Seeking More Why Women Fail/Pol Behavior Rep Files Ambitious Women 02282020")
##setwd("C:/Users/acw64/Dropbox/Seeking More Why Women Fail/Pol Behavior Rep Files Ambitious Women 02282020")

library(foreign)
library(cregg)

###


final <- read.csv("dlabss_third.csv",na.strings=c("","NA"))
dim(final)
head(final)

final$Gender <- factor(final$Gender, levels=unique(c("Male", "Female")))
final$Children <- factor(final$Children, levels=unique(c("0", "1", "2", "3")))
final$Personalistic <- factor(final$Personalistic, levels=unique(c("Empathetic", "Assertive", "Collaborative", "Determined to succeed", "Good communicator", "Hard-working", "Tough negotiator")))
final$Progressive <- factor(final$Progressive, levels=unique(c("No", "Yes")))
final$Agenda <- factor(final$Agenda, levels=unique(c("Very few changes", "Moderate changes", "A complete overhaul")))
final$PartyID <- factor(final$PartyID, levels=unique(c("Democrat", "Republican")))


library(plyr)


final$Resp_Gender <- revalue(final$Resp_Gender, c("Male"="Male", "Female"="Female", "Other/Prefer not to answer"=""))
final$Resp_Gender <- factor(final$Resp_Gender, levels=unique(c("Female", "Male")))

final$Resp_Party_Weak[final$Party=="Democrat" | final$Party.2=="Democrats"] <- "Democrat"
final$Resp_Party_Weak[final$Party=="Republican" | final$Party.2=="Republicans"] <- "Republican"
final$Resp_Party_Weak <- factor(final$Resp_Party_Weak, levels=unique(c("Democrat", "Republican")))

final2 <- final

vars <- c('chosen', "Gender", "respondent", "Children",
"Personalistic", "Progressive", "Agenda", "PartyID", "progressive_ambition", "personalistic_ambition", "agendabased_ambition", "task", "V1", "Birth.Year", "Education", "Salary", "profile", "choice", "pair", "Resp_Gender", "Resp_Party_Weak")
final <- final[,vars]
head(final)
dim(final)

#write.csv(final, "clean_dat_manipulation.csv")

##############################################################################################

library(cregg)

###########################
###Baselines
###########################


## Figure A13 Vote Choice Baseline

amces <- cj(final, chosen ~ Gender + Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent)
plot(amces, xlab="Change in Pr(Candidate Winning)")

newdat <- subset(final, task == 5)
nrow(newdat)
head(newdat)

## Figure A7 Progressive Ambition Rating DV Baseline

amces <- cj(newdat, progressive_ambition ~ Gender + Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent)
plot(amces, xlab="Change in Progressive Ambition Rating by Respondent")
amces
##let's grab coefs and pvals -- 2.974, sig at .0001

## Figure A8 Personalistic Ambition Rating DV Baseline

amces <- cj(newdat, personalistic_ambition ~ Gender + Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent)
plot(amces, xlab="Change in Personalistic Ambition Rating by Respondent")
amces
## coef is 1.69, p 1.102100e-12

## Figure A9 Agenda-Based Ambition Rating DV Baseline

amces <- cj(newdat, agendabased_ambition ~ Gender + Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent)
plot(amces, xlab="Change in Agenda-Based Ambition Rating by Respondent")


############################
####### INTERACTIONS #######
############################

library(cregg)

## Figure A18

amces <- cj(na.omit(final), chosen ~ Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent, estimate = "amce", by = ~Gender)
diff_amces <- cj(na.omit(final), chosen ~ Children + Personalistic + Progressive + Agenda + PartyID, id = ~respondent, estimate = "amce_diff", by = ~Gender)
plot(rbind(amces, diff_amces), xlab = "Effect on Pr(Candidate Selected)") + ggplot2::facet_wrap(~BY, ncol = 3L)


############################
####### Marginal Means #####
############################


#### INTERACTIONS?

final$GenderxProgressive <- with(final, interaction(Gender, Progressive), drop = TRUE)
final$GenderxAgenda <- with(final, interaction(Gender, Agenda), drop = TRUE)
final$GenderxChildren <- with(final, interaction(Gender, Children), drop = TRUE)
final$GenderxPersonalistic <- with(final, interaction(Gender, Personalistic), drop = TRUE)
final$GenderxPartyID <- with(final, interaction(Gender, PartyID), drop = TRUE)


##### PARTY

## Figure A23

mms <- cj(na.omit(final), chosen ~ GenderxProgressive + GenderxAgenda + GenderxChildren + GenderxPersonalistic + GenderxPartyID, id = ~respondent, estimate = "mm", by = ~Resp_Party_Weak)
diff_mms <- cj(na.omit(final), chosen ~ GenderxProgressive + GenderxAgenda + GenderxChildren + GenderxPersonalistic + GenderxPartyID, id = ~respondent, estimate = "mm_diff", by = ~Resp_Party_Weak)
plot(rbind(mms, diff_mms), xlab = "Effect on Pr(Candidate Selected)") + ggplot2::facet_wrap(~BY, ncol = 3L)


##### GENDER

## Figure A28

mms <- cj(na.omit(final), chosen ~ GenderxProgressive + GenderxAgenda + GenderxChildren + GenderxPersonalistic + GenderxPartyID, id = ~respondent, estimate = "mm", by = ~Resp_Gender)
diff_mms <- cj(na.omit(final), chosen ~ GenderxProgressive + GenderxAgenda + GenderxChildren + GenderxPersonalistic + GenderxPartyID, id = ~respondent, estimate = "mm_diff", by = ~Resp_Gender)
plot(rbind(mms, diff_mms), xlab = "Effect on Pr(Candidate Selected)") + ggplot2::facet_wrap(~BY, ncol = 3L)









